package models

import (
	"fmt"
	"gitchina/kly_service/data"
	"gitchina/kly_service/errors"
	"gitchina/kly_service/util"
	"math/rand"
	"strconv"
	"strings"
	"time"
)

type CarrierPubRQ struct {
	Id                ID      `json:"pub_id"`
	StartArea         string  `json:"start_area"`
	EndArea           string  `json:"end_area"`
	ShipmentTime      string  `json:"shipment_time"`
	Load              int     `json:"load"`
	Price             float32 `json:"price"`
	SrcGeo            string  `json:"src_geo"`
	DestGeo           string  `json:"dest_geo"`
	SrcLocationTitle  string  `json:"src_location_title"`
	DestLocationTitle string  `json:"dest_location_title"`
	SrcLocation       string  `json:"src_location"`
	DestLocation      string  `json:"dest_location"`
}

type CarrierPubRS struct {
	Id                ID      `json:"carrier_pub_id"`
	StartArea         string  `json:"start_area"`
	EndArea           string  `json:"end_area"`
	ShipmentTime      string  `json:"shipment_time"`
	Load              int     `json:"vehicle_load"`
	State             int     `json:"state"`
	Price             float32 `json:"price"`
	SrcGeo            string  `json:"src_geo,omitempty"`
	DestGeo           string  `json:"dest_geo,omitempty"`
	SrcLocationTitle  string  `json:"src_location_title,omitempty"`
	DestLocationTitle string  `json:"dest_location_title,omitempty"`
	SrcLocation       string  `json:"src_location,omitempty"`
	DestLocation      string  `json:"dest_location,omitempty"`
}

type CarrierPubHistoryRS struct {
	TotalCount int            `json:"total_count"`
	List       []CarrierPubRS `json:"pub_list"`
}

type GetCarrierPubRQ struct {
	Id ID `json:"carrier_pub_id"`
}

type QueryCarrierPubListRQ struct {
	StartArea   string `json:"start_area"`
	EndArea     string `json:"end_area"`
	TimeBegin   string `json:"time_begin"`
	TimeEnd     string `json:"time_end"`
	VehicleType string `json:"vehicle_type"`
	VehicleLen  string `json:"vehicle_len"`
	VehicleLoad string `json:"vehicle_load"`
	Type        int    `json:"type"`
	PageNo      int    `json:"page_no"`
	PageSize    int    `json:"page_size"`
}

type QueryCarriersRQ struct {
	VehicleType       string `json:"vehicle_type"`
	VehicleLoad       string `json:"vehicle_load"`
	VehicleLen        string `json:"vehicle_len"`
	FrequentLineStart string `json:"frequent_line_start"`
	FrequentLineEnd   string `json:"frequent_line_end"`
	Type              int    `json:"type"`
	PageNo            int    `json:"page_no"`
	PageSize          int    `json:"page_size"`
}

type CarrierListRS struct {
	TotalCount int           `json:"total_count"`
	ListCount  int           `json:"list_count"`
	List       []CarrierList `json:"pub_list"`
}

type CarrierList struct {
	OwnerName         string `json:"owner_name"`
	OwnerId           ID     `json:"owner_id"`
	AuthState         int    `json:"auth_state"`
	VehiclePhotoUrl   string `json:"vehicle_photo"`
	VehicleType       string `json:"vehicle_type"`
	VehicleLen        string `json:"vehicle_len"`
	VehicleLoad       string `json:"vehicle_load"`
	FrequentLineStart string `json:"frequent_line_start"`
	FrequentLineEnd   string `json:"frequent_line_end"`
	CreateTime        string `json:"create_time"`
	Photo             string `json:"member_photo"`
	Phone             string `json:"phone"`
	Score             string `json:"score"`
	Type              int    `json:"type"`
}

type CarrierPubListRS struct {
	TotalCount int              `json:"total_count"`
	List       []CarrierPubList `json:"pub_list"`
}

type CarrierPubList struct {
	OwnerName         string  `json:"owner_name"`
	OwnerStars        int     `json:"owner_stars"`
	OwnerPhone        string  `json:"owner_phone"`
	OwnerId           ID      `json:"owner_id"`
	CarrierPubId      ID      `json:"carrier_pub_id"`
	StartArea         string  `json:"start_area"`
	EndArea           string  `json:"end_area"`
	VehicleType       string  `json:"vehicle_type"`
	VehicleLen        string  `json:"vehicle_len"`
	VehicleLoad       string  `json:"vehicle_load"`
	VehiclePhotoUrl   string  `json:"vehicle_photo"`
	ShipmentTime      string  `json:"shipment_time"`
	Price             float32 `json:"price"`
	SrcGeo            string  `json:"src_geo"`
	DestGeo           string  `json:"dest_geo"`
	SrcLocationTitle  string  `json:"src_location_title"`
	DestLocationTitle string  `json:"dest_location_title"`
	SrcLocation       string  `json:"src_location"`
	DestLocation      string  `json:"dest_location"`
	Type              int     `json:"type"`
}

type CarrierPubDetailRS struct {
	Name              string  `json:"name"`
	OwnerPhone        string  `json:"phone"`
	OwnerStars        int     `json:"stars"`
	CarrierPubId      string  `json:"carrier_pub_id"`
	MemberId          string  `json:"owner_id"`
	StartArea         string  `json:"start_area"`
	EndArea           string  `json:"end_area"`
	Price             float32 `json:"price"`
	ShipmentTime      string  `json:"shipment_time"`
	VehicleType       string  `json:"vehicle_type"`
	VehicleLen        string  `json:"vehicle_len"`
	VehicleLoad       string  `json:"vehicle_load"`
	VehicleNo         string  `json:"vehicle_no"`
	CargoType         string  `json:"cargo_type"`
	MemberPhotoUrl    string  `json:"owner_photo_url"`
	SrcGeo            string  `json:"src_geo"`
	DestGeo           string  `json:"dest_geo"`
	SrcLocationTitle  string  `json:"src_location_title"`
	DestLocationTitle string  `json:"dest_location_title"`
	SrcLocation       string  `json:"src_location"`
	DestLocation      string  `json:"dest_location"`
	FrequentLineStart string  `json:"frequent_line_start"`
	FrequentLineEnd   string  `json:"frequent_line_end"`
	Type              int     `json:"type"`
}

func init() {
	go autoActiveExpired()
}

func (l Logistics) CarrierPub(mbrId ID, rq *CarrierPubRQ, ignoreLimit bool) (pubId ID, err error) {
	var id int64
	// var minPriceAmount float64
	// var general General
	var authState string
	var srcCounty, srcCity, srcProvince, destCounty, destCity, destProvince int
	//var shipmentTime time.Time
	var repo data.LogisticsRepo
	var mbrRepo data.MemberRepo

	if srcCounty, err = strconv.Atoi(rq.StartArea); err != nil || srcCounty == 0 {
		err = errors.New(errors.MSG_Logi_Invalid_Start_Area)
		return
	}

	if destCounty, err = strconv.Atoi(rq.EndArea); err != nil {
		err = errors.New(errors.MSG_Logi_Invalid_End_Area)
		return
	}

	// if destCounty, err = strconv.Atoi(rq.EndArea); err != nil || destCounty == 0 {
	// 	err = errors.New(errors.MSG_Logi_Invalid_End_Area)
	// 	return
	// }

	if rq.ShipmentTime == "" {
		rq.ShipmentTime = "2100-01-01 00:00:00"
	}

	if _, err = time.Parse("2006-01-02 15:04:05", rq.ShipmentTime); err != nil {
		err = errors.New(errors.MSG_Logi_Invalid_Shipment_Time)
		return
	}

	//if time.Now().Sub(shipmentTime) >= 0 {
	//	err = errors.New(errors.MSG_Logi_Invalid_Shipment_Time)
	//	return
	//}

	if _, _, _, id, err = mbrId.Decode(); err != nil {
		err = errors.New(errors.MSG_Mbr_Invalid)
		return
	}

	// if minPriceAmount, err = strconv.ParseFloat(general.GetParams("min_price_amount"), 32); err == nil {
	// 	if float64(rq.Price) < minPriceAmount {
	// 		err = errors.New(fmt.Sprintf("%s%v元", errors.MSG_Order_Price_Amount_Not_Less_Than, minPriceAmount))
	// 		return
	// 	}
	// }

	if srcCounty%10000 == 0 {
		srcProvince = srcCounty
		srcCity = 0
		srcCounty = 0
	} else if srcCounty%100 == 0 {
		srcProvince = srcCounty - srcCounty%10000
		srcCity = srcCounty
		srcCounty = 0
	} else {
		srcProvince = srcCounty - srcCounty%10000
		srcCity = srcCounty - srcCounty%100
	}

	if destCounty%10000 == 0 {
		destProvince = destCounty
		destCity = 0
		destCounty = 0
	} else if destCounty%100 == 0 {
		destProvince = destCounty - destCounty%10000
		destCity = destCounty
		destCounty = 0
	} else {
		destProvince = destCounty - destCounty%10000
		destCity = destCounty - destCounty%100
	}

	if _, authState, _, _, err = mbrRepo.GetAuthState(int(id)); err != nil {
		util.GetLogger().Error("[model-LinePub] - error:%s", err.Error())
		err = errors.New(errors.MSG_Logi_Line_Pub_Add_Error)
		return
	}

	if authState != "2" {
		err = errors.New(errors.MSG_Mbr_Upd_Info_Not_Allowed)
		return
	}

	var m Member
	var carrierType int
	info, err := m.GetMemberInfo(mbrId)
	if err != nil {
		err = errors.New(errors.MSG_Mbr_Invalid)
		return
	}
	if info.MemberType == 4 {
		carrierType = 2
	} else {
		carrierType = 1
	}

	pub := &data.CarrierPubDto{
		MemberId:          int(id),
		SrcProvince:       srcProvince,
		SrcCity:           srcCity,
		SrcCounty:         srcCounty,
		DestProvince:      destProvince,
		DestCity:          destCity,
		DestCounty:        destCounty,
		Price:             rq.Price,
		ShipmentTime:      rq.ShipmentTime,
		VehicleLoad:       rq.Load,
		State:             0,
		SrcGeo:            rq.SrcGeo,
		DestGeo:           rq.DestGeo,
		SrcLocationTitle:  rq.SrcLocationTitle,
		DestLocationTitle: rq.DestLocationTitle,
		SrcLocation:       rq.SrcLocation,
		DestLocation:      rq.DestLocation,
		Type:              carrierType,
	}

	if rq.Id == "" {
		var pubCount int
		if ignoreLimit {
			if id, err = repo.AddCarrierPub(pub); err == nil {
				pubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, id)
			}
		} else {
			if pubCount, err = repo.GetCarrierPubCount(int(id)); err == nil {
				if pubCount < 3 {
					if id, err = repo.AddCarrierPub(pub); err == nil {
						pubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, id)
					}
				} else {
					err = errors.New(errors.MSG_Logi_Too_Many_Carrier_Pubs)
					return
				}
			}
		}
	} else {
		var pid int64
		if _, _, _, pid, err = rq.Id.Decode(); err == nil && pid != 0 {
			pub.Id = int(pid)
			if err = repo.UpdateCarrierPub(pub); err == nil {
				pubId = rq.Id
			}
		} else {
			err = fmt.Errorf("invalid pub id:%s", rq.Id)
		}
	}

	if err != nil {
		util.GetLogger().Error("[model - CarrierPub] - error: %s", err.Error())
		err = errors.New(errors.MSG_Logi_Carrier_Pub_AddOrUpdate_Error)
	}

	// var pid int64
	// if _, _, _, pid, err = rq.Id.Decode(); err != nil {

	// }

	// if err == nil {
	// 	pubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, id)
	// } else {
	// 	util.GetLogger().Error("[model - CarrierPub] - error: %s", err.Error())
	// 	err = errors.New(errors.MSG_Logi_Carrier_Pub_AddOrUpdate_Error)
	// }

	return
}

func (L Logistics) CancelCarrierPub(mbrId, carrierPubId ID) (err error) {
	var repo data.LogisticsRepo
	var mId, pubId int64
	if _, _, _, mId, err = mbrId.Decode(); err != nil {
		err = errors.New(errors.MSG_Mbr_Invalid)
		return
	}

	if _, _, _, pubId, err = carrierPubId.Decode(); err != nil {
		err = errors.New(errors.MSG_Logi_Invalid_Pub_Id)
		return
	}

	if err = repo.CancelCarrierPub(int(mId), int(pubId)); err != nil {
		util.GetLogger().Error("[model-CancelCarrierPub] - error:%s", err.Error())
	}
	return
}

func (l Logistics) GetCarrierPub(mbrId ID) (rs CarrierPubRS, err error) {
	var pub data.CarrierPubDto
	var repo data.LogisticsRepo
	_, _, _, id, err := mbrId.Decode()
	if err != nil {
		err = errors.New(errors.MSG_Mbr_Invalid)
	} else {
		if pub, err = repo.GetCarrierPub(int(id)); err == nil {
			var pubId ID
			pubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, int64(pub.Id))
			rs.Id = pubId
			rs.State = pub.State
			rs.Price = pub.Price
			rs.Load = pub.VehicleLoad
			rs.ShipmentTime = pub.ShipmentTime
			rs.StartArea = l.chooseArea(pub.SrcProvince, pub.SrcCity, pub.SrcCounty)
			rs.EndArea = l.chooseArea(pub.DestProvince, pub.DestCity, pub.DestCounty)
		} else {
			util.GetLogger().Error("[model-GetCarrierPub] - error:%s", err.Error())
			err = nil
		}
	}
	return
}

func (l Logistics) GetCarrierPubList(mbrId ID, listType int) (rs CarrierPubHistoryRS, err error) {
	var pubId ID
	var list []data.CarrierPubDto
	var repo data.LogisticsRepo
	_, _, _, id, err := mbrId.Decode()
	if err != nil {
		err = errors.New(errors.MSG_Mbr_Invalid)
	} else {
		if listType == 1 {
			//active
			list, err = repo.GetActiveCarrierPub(int(id))
		} else {
			//history
			list, err = repo.GetCarrierPubHistory(int(id))
		}
		if err == nil {
			rs = CarrierPubHistoryRS{TotalCount: len(list), List: make([]CarrierPubRS, len(list))}
			for i, p := range list {
				pubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, int64(p.Id))
				pub := CarrierPubRS{
					Id:                pubId,
					State:             p.State,
					Price:             p.Price,
					Load:              p.VehicleLoad,
					ShipmentTime:      p.ShipmentTime,
					StartArea:         l.chooseArea(p.SrcProvince, p.SrcCity, p.SrcCounty),
					EndArea:           l.chooseArea(p.DestProvince, p.DestCity, p.DestCounty),
					SrcGeo:            p.SrcGeo,
					DestGeo:           p.DestGeo,
					SrcLocationTitle:  p.SrcLocationTitle,
					DestLocationTitle: p.DestLocationTitle,
					SrcLocation:       p.SrcLocation,
					DestLocation:      p.DestLocation,
				}
				rs.List[i] = pub
			}
		} else {
			util.GetLogger().Error("[model-GetCarrierPub] - error:%s", err.Error())
			err = nil
		}
	}
	return
}

func (l Logistics) QueryCarriers(rq QueryCarriersRQ) (rs CarrierListRS, err error) {
	var list []data.CarrierListDto
	var repo data.LogisticsRepo
	var rowCount int
	var totalCount int
	param := l.getQueryCarrierCond(rq)
	if list, rowCount, err = repo.QueryCarrierList(param); err == nil {
		pubs := make([]CarrierList, len(list))
		for idx, dto := range list {
			var mbrId ID
			mbrId.Encode(ID_Shard, ID_Ver, ID_Member_Category, int64(dto.OwnerId))
			pubs[idx] = CarrierList{
				OwnerName:         dto.OwnerName,
				OwnerId:           mbrId,
				AuthState:         dto.AuthState,
				VehicleType:       dto.VehicleType,
				VehicleLen:        dto.VehicleLen,
				VehicleLoad:       dto.VehicleLoad,
				VehiclePhotoUrl:   dto.VehiclePhotoUrl,
				FrequentLineStart: dto.FrequentLineStart,
				FrequentLineEnd:   dto.FrequentLineEnd,
				CreateTime:        dto.CreateTime,
				Photo:             dto.Photo,
				Phone:             dto.Phone,
			}
			if dto.ScoreCount == 0 {
				pubs[idx].Score = "0"
			} else {
				pubs[idx].Score = fmt.Sprintf("%.0f", float32(dto.ScoreTotal)/float32(dto.ScoreCount))
			}
		}
		if totalCount, err = repo.GetCarrierTotalCount(); err != nil {
			util.GetLogger().Error("[data.QueryCarriers] - error:%s", err.Error())
		}
		rs = CarrierListRS{TotalCount: totalCount, ListCount: rowCount, List: pubs}
	} else {
		util.GetLogger().Error("[data.QueryCarriers] - error:%s", err.Error())
		err = nil
	}
	return
}

func (l Logistics) QueryCarrierPubList(rq QueryCarrierPubListRQ) (rs CarrierPubListRS, err error) {
	var list []data.CarrierPubListDto
	var repo data.LogisticsRepo
	var rowCount int
	param := l.getQueryCarrierPubListCond(rq)
	if list, rowCount, err = repo.QueryCarrierPubList(param); err == nil {
		pubs := make([]CarrierPubList, len(list))
		for idx, dto := range list {
			var carrierPubId, mbrId ID
			carrierPubId.Encode(ID_Shard, ID_Ver, ID_Carrier_Pub_Category, int64(dto.CarrierPubId))
			mbrId.Encode(ID_Shard, ID_Ver, ID_Member_Category, int64(dto.OwnerId))

			pubs[idx] = CarrierPubList{
				OwnerName:         dto.OwnerName,
				OwnerStars:        dto.OwnerStars,
				OwnerPhone:        dto.OwnerPhone,
				OwnerId:           mbrId,
				CarrierPubId:      carrierPubId,
				VehicleType:       dto.VehicleType,
				VehicleLen:        dto.VehicleLen,
				VehicleLoad:       dto.VehicleLoad,
				VehiclePhotoUrl:   dto.VehiclePhotoUrl,
				ShipmentTime:      dto.ShipmentTime,
				Price:             dto.Price,
				SrcGeo:            dto.SrcGeo,
				DestGeo:           dto.DestGeo,
				SrcLocationTitle:  dto.SrcLocationTitle,
				DestLocationTitle: dto.DestLocationTitle,
				SrcLocation:       dto.SrcLocation,
				DestLocation:      dto.DestLocation,
				Type:              dto.Type,
			}

			pubs[idx].StartArea = l.chooseArea(dto.SrcProvince, dto.SrcCity, dto.SrcCounty)
			pubs[idx].EndArea = l.chooseArea(dto.DestProvince, dto.DestCity, dto.DestCounty)
		}
		rs = CarrierPubListRS{TotalCount: rowCount, List: pubs}
	} else {
		util.GetLogger().Error("[model-QueryCarrierPubList] - error:%s", err.Error())
		err = nil
	}
	return
}

func (l Logistics) GetCarrierPubDetail(pubId ID) (rs CarrierPubDetailRS, err error) {
	var pub data.CarrierPubDetail
	var repo data.LogisticsRepo
	_, _, _, id, err := pubId.Decode()
	if err != nil {
		err = errors.New(errors.MSG_Logi_Invalid_Pub_Id)
	} else {
		var mbrId ID
		if pub, err = repo.GetCarrierPubDetail(int(id)); err == nil {
			mbrId.Encode(ID_Shard, ID_Ver, ID_Member_Category, int64(pub.MemberId))
			rs.Name = pub.Name
			rs.OwnerPhone = pub.OwnerPhone
			rs.OwnerStars = pub.OwnerStars
			rs.CarrierPubId = string(pubId)
			rs.MemberId = string(mbrId)
			rs.VehicleType = pub.VehicleType
			rs.VehicleLen = pub.VehicleLen
			rs.VehicleNo = pub.VehicleNo
			rs.VehicleLoad = pub.VehicleLoad
			rs.Price = pub.Price
			rs.VehicleLoad = pub.VehicleLoad
			rs.ShipmentTime = pub.ShipmentTime
			rs.MemberPhotoUrl = pub.MemberPhotoUrl
			rs.CargoType = ""
			rs.SrcGeo = pub.SrcGeo
			rs.DestGeo = pub.DestGeo
			rs.SrcLocationTitle = pub.SrcLocationTitle
			rs.DestLocationTitle = pub.DestLocationTitle
			rs.SrcLocation = pub.SrcLocation
			rs.DestLocation = pub.DestLocation
			rs.StartArea = l.chooseArea(pub.SrcProvince, pub.SrcCity, pub.SrcCounty)
			rs.EndArea = l.chooseArea(pub.DestProvince, pub.DestCity, pub.DestCounty)
			rs.FrequentLineStart = pub.FrequentLineStart
			rs.FrequentLineEnd = pub.FrequentLineEnd
			rs.Type = pub.Type
		} else {
			util.GetLogger().Error("[model-GetCarrierPubDetail] - error:%s", err.Error())
			err = nil
		}
	}
	return
}

func (l Logistics) getQueryCarrierCond(rq QueryCarriersRQ) data.QueryCarrierParam {
	var param data.QueryCarrierParam
	if _, err := strconv.Atoi(rq.VehicleLen); err == nil {
		param.VehicleLen = rq.VehicleLen
	}
	if _, err := strconv.Atoi(rq.VehicleLoad); err == nil {
		param.VehicleLoad = rq.VehicleLoad
	}
	if _, err := strconv.Atoi(rq.VehicleType); err == nil {
		param.VehicleType = rq.VehicleType
	}
	lineStart := strings.TrimSpace(rq.FrequentLineStart)
	lineEnd := strings.TrimSpace(rq.FrequentLineEnd)

	if lineStart != "" {
		param.FrequentLineStart = lineStart
	}
	if lineEnd != "" {
		param.FrequentLineEnd = lineEnd
	}

	if rq.PageNo >= 1 {
		param.PageNo = rq.PageNo
	} else {
		param.PageNo = 1
	}
	if rq.PageSize >= 1 && rq.PageSize <= 20 {
		param.PageSize = rq.PageSize
	} else {
		param.PageSize = 10
	}

	if rq.Type == 2 {
		param.Type = 4
	} else {
		param.Type = 2
	}

	return param
}

func (l Logistics) getQueryCarrierPubListCond(rq QueryCarrierPubListRQ) data.QueryCarrierPubListParam {
	var param data.QueryCarrierPubListParam
	if startAreaId, err := strconv.Atoi(rq.StartArea); err == nil {
		param.StartArea = startAreaId
	}
	if endAreaId, err := strconv.Atoi(rq.EndArea); err == nil {
		param.EndArea = endAreaId
	}

	if rq.Type == 0 {
		rq.Type = 1
	}
	param.Type = rq.Type

	tb, eb := time.Parse("2006-01-02", rq.TimeBegin)
	te, ee := time.Parse("2006-01-02", rq.TimeEnd)

	if eb != nil && ee != nil {
		param.TimeBegin = time.Now().AddDate(0, 0, -7).Format("2006-01-02 00:00:00")
		param.TimeEnd = time.Now().AddDate(0, 0, 8).Format("2006-01-02 00:00:00")
	} else if eb == nil && ee != nil {
		param.TimeBegin = tb.Format("2006-01-02 00:00:00")
		param.TimeEnd = time.Now().AddDate(1, 0, 0).Format("2006-01-02 00:00:00")
	} else if eb != nil && ee == nil {
		param.TimeBegin = time.Now().AddDate(-1, 0, 0).Format("2006-01-02 00:00:00")
		param.TimeEnd = te.AddDate(0, 0, 1).Format("2006-01-02 00:00:00")
	} else {
		param.TimeBegin = tb.Format("2006-01-02 00:00:00")
		param.TimeEnd = te.AddDate(0, 0, 1).Format("2006-01-02 00:00:00")
	}

	if _, err := strconv.Atoi(rq.VehicleType); err == nil {
		param.VehicleType = rq.VehicleType
	}
	if _, err := strconv.Atoi(rq.VehicleLoad); err == nil {
		param.VehicleLoad = rq.VehicleLoad
	}
	if _, err := strconv.Atoi(rq.VehicleLen); err == nil {
		param.VehicleLen = rq.VehicleLen
	}
	if rq.PageNo >= 1 {
		param.PageNo = rq.PageNo
	} else {
		param.PageNo = 1
	}
	if rq.PageSize >= 1 && rq.PageSize <= 20 {
		param.PageSize = rq.PageSize
	} else {
		param.PageSize = 10
	}

	return param
}

func autoActiveExpired() {
	var repo data.LogisticsRepo
	rand.Seed(time.Now().Unix())
	t1 := time.NewTimer(8*time.Minute + time.Duration(rand.Intn(100))*time.Second)
	for {
		select {
		case <-t1.C:
			if err := repo.ActiveExpiredCarrier(); err != nil {
				util.GetLogger().Error("[autoActiveExpired] - error:%s", err.Error())
			}
			rand.Seed(time.Now().Unix())
			t1.Reset(8*time.Minute + time.Duration(rand.Intn(100))*time.Second)
		}
	}
}
